# -*- coding: utf-8 -*-
# Created by zhangyanqi on 2018/4/17

"""
给定一个字符串，找到它的第一个不重复的字符，并返回它的索引。如果不存在，则返回 -1。

案例:

s = "leetcode"
返回 0.

s = "loveleetcode",
返回 2.


注意事项：您可以假定该字符串只包含小写字母。
"""


class Solution:
    def firstUniqChar(self, s):
        """
        :type s: str
        :rtype: int
        """
        l = list(s)
        temp = []
        not_uniq = []
        temp_index = 0
        for char in l:
            temp.append(char)
            if temp.index(char) != temp_index:
                not_uniq.append(char)
            temp_index += 1
        for char in temp:
            try:
                not_uniq.index(char)
            except Exception:
                return l.index(char)
        return -1

if __name__ == "__main__":
    s = Solution()
    char = s.firstUniqChar("111")
    print(char)
